package com.atguigu.tingshu.search.receiver;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.search.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AlbumIndexReceiver {

    @Autowired
    private SearchService searchService;

    /**
     * 专辑上架
     * @param msg
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upper(ConsumerRecord<String,String> msg){
        String value = msg.value();
        if(value != null){
            Long albumId = Long.valueOf(value);
            searchService.upperAlbum(albumId);
        }
    }

    /**
     * 专辑下架
     * @param msg
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lower(ConsumerRecord<String,String> msg){
        String value = msg.value();
        if(value != null){
            Long albumId = Long.valueOf(value);
            searchService.lowerAlbum(albumId);
        }
    }
}
